#!/usr/bin/env python3
#coding=utf-8

from scapy.all import *
import debugpy
debugpy.listen(6688)

# 定义要监听的IP地址和端口号
ip = "192.168.1.127"
port = 514

# 定义要嗅探的网卡
iface = "eth0"

# 定义回调函数，处理嗅探到的数据包
def packet_callback(packet):
    if packet.haslayer(UDP) and packet[UDP].dport == port:
        print("Received UDP packet on port {}".format(port))
        print(packet.summary())
        print(packet.load.decode('utf-8'))

# 创建一个回调函数，用于处理捕获到的数据包
sniff(iface=iface, filter="udp port {}".format(port), prn=packet_callback)
